A thread is a unit of flow run in a process, and is information needed for handling a particular service request. The thread includes a program counter, a register set, a stack, and a thread ID for handling a particular service request, and also shares resources like code, data, and files with other thread.
Every time a request is acquired from a client, a conventional server creates a thread and processes the request by using the thread, and this mechanism is effective enough to perform most of tasks. However, in case of a server having massive connections with clients, a time required for creating and discarding threads exceeds a time for processing requests, which causes lower-than-usual performance of a system. Further, when the requests from the clients rise abruptly, creating threads for each of the requests makes the number of the threads also rise excessively, and this necessitates scheduling which results in an overhead of the system.
To solve such a problem, a thread pool was suggested in which a limited number of threads is created in advance and the threads are reused without being discarded.
The thread pool is a thread set which includes at least one thread, in which used threads are not discarded but allocated to other tasks to thereby be reused. Specifically, the way the thread pool works is as follows: the thread pool provides a processor with a thread to allow the processor to execute a specific task, and if the processor finishes the specific task and returns the thread to the thread pool, the thread pool awaits till it receives another task.
The thread pool manages information on a minimum size (minimum thread value) of threads which it should keep at minimum, and information on a maximum size (maximum thread value) of threads which is a maximum number of threads it can create. However, it is very difficult to determine the appropriate numbers of the minimum thread value and the maximum thread value that optimize the performance of a server.
A conventional method was mostly: pre-setting the minimum thread value and the maximum thread value according to number and types of service requests, measuring performance, and determining the optimal number of threads utilizing the measured performance. However, such a method which depends on a performance record is not suitable for determining appropriate minimum or a maximum thread values because time for proper experiment is required for accumulation of the performance record and even then accuracy of the record is not guaranteed in a web environment that changes fast in real-time.
Further, according to another conventional technique, when the number of the threads is increased, whether the size of the task queue decreases is determined, and if the size decreases, the maximum thread value at the time is determined to be acceptable and the number of the threads is not increased any more. However, it has a disadvantage of uninterrupted increase of the sizes of the threads and the task queues if the CPU usage is at one hundred percent, as capacity to process requests does not change even though the number of the threads is increased.
Therefore, the inventor of the present invention suggests a method and a computing device for dynamically managing the size of the thread pool by using the number of requests outputted from the task queues.